package com.shqcjd.preinstallmobile.ui.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.preinstallmobile.R;
import com.shqcjd.preinstallmobile.model.pojo.FileBean;
import com.shqcjd.preinstallmobile.util.DateUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sy on 2019/3/21.
 */

public class RemoteFileListAdapter extends BaseQuickAdapter<FileBean,RemoteFileListAdapter.ViewHolder> {

    public RemoteFileListAdapter() {
        super(R.layout.item_remote_file);
    }

    @Override
    protected void convert(RemoteFileListAdapter.ViewHolder helper, FileBean item) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_default_small)	//加载成功之前占位图
                .error(R.mipmap.ic_default_small)	//加载错误之后的错误图
//                .override(35,35)	//指定图片的尺寸
                .centerCrop();//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都
        switch (item.extension) {
            case ".png":
            case ".jpg":
                Glide.with(mContext)
                        .load(item.url)
                        .apply(options)
                        .into(helper.iv_img);
                break;
            case ".txt":
            case ".doc":
                Glide.with(mContext)
                        .load(R.mipmap.ic_word)
                        .into(helper.iv_img);
                break;
            case ".mp4":
                Glide.with(mContext)
                        .asBitmap()
                        .load(item.url)
                        .apply(options)
                        .into(helper.iv_img);
                break;
        }


        helper.tv_name.setText(item.filename);
        helper.tv_time.setText(DateUtil.getDateToString(item.uploadTime,"yyyy-MM-dd HH:mm:ss"));

    }

    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.iv_img)
        ImageView iv_img;
        @BindView(R.id.tv_name)
        TextView tv_name;
        @BindView(R.id.tv_time)
        TextView tv_time;
        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}